import Warning from 'components/Markdown/Warning'

export const meta = {
  title: "CLI Command Reference",
  position: 60,
}

## prisma init

Launches an interactive CLI wizard helping you to bootstrap the service configuration for a new Prisma service. 

The generated files are:

- prisma.yml
- datamodel.graphql
- docker-compose.yml (optional)

If you provide a directory name as an argument to the command, the generated files will be placed inside a new directory with that name.

### Usage

```bash
prisma init DIRNAME
```

### Examples

**Create service configuration for Prisma service in a directory called `myapp`**

```bash
prisma init myapp
```

## prisma deploy

Deploys a service configuration to a Prisma service. 

Every time you're changing a file deom your service configuration, you need to synchronize these changes with the running Prisma service.

Upon the very first deploy of a service, the command will perform initial data seeding if the `seed` property in prisma.yml is provided. You can prevent this by passing the `--no-seed` option.

If no [`endpoint`](5cy7#endpoint-optional) property is specifed in prisma.yml, the command will prompt you to interactively select a Prisma server as a deployment target for the service. After you selected a Prisma server, the CLI writes the `endpoint` into prisma.yml as the default for future deploys. To bring up the interactive prompt again, simply remove the `endpoint` property from prisma.yml manually or pass the `--new` option.

### Usage

```bash
prisma deploy [flags]
```

### Flags

```
-d, --dry-run              Perform a dry-run of the deployment
-e, --env-file ENV-FILE    Path to .env file to inject env vars
-f, --force                Accept data loss caused by schema changes
-j, --json                 JSON Output
-n, --new                  Force interactive mode to select the cluster
-w, --watch                Watch for changes
--no-seed                  Disable seed on initial service deploy
```

### Examples

**Deploy service configuration in current directory**

```bash
prisma deploy
```

**Deploy service and interactively select a Prisma server as deployment target**:

```bash
prisma deploy --new
```

**Deploy service with environment variables specified in `.env.prod`**

```bash
prisma deploy --env-file .env.prod
```


## prisma introspect

Creates a [data model](knul) by _introspecting_ the schema of an existing database.

<Warning>

`prisma introspect` currently only works for Postgres databases.

</Warning>

The command launches an interactive wizard asking you to provide your database connection details:

- **Host**: The host of your Postgres server, e.g. `localhost`.
- **Port**: The port where your Postgres server listens, e.g. `5432`.
- **User & Password**: The credentials for your Postgres server.
- **Name of existing _database_**: The name of the Postgres _database_.
- **Use SSL (Yes/No)**: If your database connection is using SSL, you need to select `Yes`, otherwise `No`.
- **Name of existing _schema_**: The name of the Postgres _schema_, e.g. `public`.

Learn more about database introspection with Prisma [here](soi1).

### Usage

```sh
prisma introspect
```

### Examples

**Introspect an existing database**

```sh
prisma introspect
```

Here is a sample interaction where the database connection details are provided through the wizard:

```
? What kind of database do you want to introspect? Postgres
? Enter database host localhost
? Enter database port 5432
? Enter database user prisma
? Enter database password ****
? Enter name of existing database prisma-db
? Enter name of existing schema public

Introspecting database 402ms
Created datamodel mapping based on 7 database tables.

Created 1 new file:               

  datamodel-[TIMESTAMP].graphql    GraphQL SDL-based datamodel (derived from existing database)
```

The generated datamodel file will contain a timestamp in its name to avoid overriding your existing `datamodel.graphql` file.


## prisma info

Display service information:

- Service name
- Service stage
- API endpoints (HTTP and Websocket)

### Usage

```bash
prisma info
```

### Flags

```
 -e, --env-file ENV-FILE    Path to .env file to inject env vars
 -j, --json                 JSON Output
 -s, --secret               Print secret in JSON output (requires --json option)
```

### Examples

**Print information about current service**

```bash
prisma info
```

**Print information about current service in JSON**

```bash
prisma info --json
```

**Print information about current service in JSON and include service secret**

```bash
prisma info --json --secret
```

> The service secret is only printed if both the `--json` and `--secret` flags are provided.

## prisma token

Generate a new [service token](ghd4#service-token). The service token is a [JWT](https://jwt.io) that is _signed_ with the [service secret](ghd4#service-secret).

### Usage

```bash
prisma token [flags]
```

### Flags

```
-c, --copy                 Copy token to clipboard
-e, --env-file ENV-FILE    Path to .env file to inject env vars
```

### Examples

**Print service token**

```bash
prisma token
```

**Copy service token to clipboard**

```bash
prisma token --copy
```

## prisma list

List all deployed services.

### Usage

```sh
prisma list
```

### Examples

**List all deployed services**

```sh
prisma list
```

### prisma delete

Delete an existing service from the Prisma server its running on. 

This command needs to be executed inside the root directory of the Prisma service you want to delete (as the CLI needs access to the service's prisma.yml).

### Usage

```sh
prisma delete [flags]
```

### Flags

```
 -e, --env-file ENV-FILE    Path to .env file to inject env vars
 -f, --force                Force delete, without confirmation
```

### Examples

**Delete an existing service (with confirmation prompt)**

```sh
prisma delete
```

**Delete an existing service (without confirmation prompt)**

```sh
prisma delete --force
```

## prisma playground

Opens a [GraphQL Playground](https://github.com/prismagraphql/graphql-playground) for the current service. 

By default, this opens the _Desktop version_ of the Playground (if installed). The browser-based Playground can be opened by passing the `--web` flag.

The Playground is running on port `3000`.

### Usage

```sh
prisma playground [flags]
```

### Flags

```
--dotenv DOTENV          Path to .env file to inject env vars
-w, --web                Open browser-based Playground
```

### Examples

**Open Playground (Desktop version, if installed)**

```sh
prisma playground
```

**Open Playground (browser-based version)**

```sh
prisma playground --web
```

## prisma seed

Seeds the service with data. 

This command expects that the [`seed`](5cy7#seed-optional) property in prisma.yml is specified.

#### Usage

```sh
prisma seed [flags]
```

#### Flags

```
-e, --env-file ENV-FILE    Path to .env file to inject env vars
-r, --reset                Reset the service before seeding
```

#### Examples

**Seed service with initial data**

```sh
prisma seed
```

**Seed service with initial data after deleting all of the service's data first**

```sh
prisma seed --reset
```

## prisma import

Imports data into the database of your Prisma service. 

The data needs to be formatted according to the [Normalized Data Format](jsw9#normalized-data-format). For more info, read the [Data Import & Export](jsw9) page.

### Usage

```sh
prisma import [flags]
```

### Flags

```
-d, --data PATH            (required) Path to zip or directory with import data (NDF)
-e, --env-file ENV-FILE    Path to .env file to inject env vars
```

## prisma export

Exports your service data to a local zip directory. For more info, read the [Data Import & Export](jsw9) page.

### Usage

```sh
prisma export [flags]
```

### Flags

```
-e, --env-file ENV-FILE    Path to .env file to inject env vars
-p, --path PATH            Path to export .zip file
```

### Examples

**Export data to file with default name (`export-<timestamp>.zip`)**

```sh
prisma export
```

**Export data to file called `mydata.zip`**

```sh
prisma export --path mydata.zip
```

## prisma reset

Delete all service data.

### Usage

```sh
prisma reset [flags]
```

### Flags

```
 -e, --env-file ENV-FILE    Path to .env file to inject env vars
 -f, --force                Force reset data without confirmation
```

### Examples

**Delete all of the service's data (with confirmation prompt).**

```sh
prisma reset
```

**Delete all of the service's data (without confirmation prompt).**

```sh
prisma reset --force
```

## prisma login

Authenticate with [Prisma Cloud](https://www.prisma.io/cloud). 

This command opens the [Prisma Cloud Console](https://app.prisma.io/) where you need to sign up or sign in.

After a successful authentication in the browser, the CLI writes the `cloudSessionKey` into `~/.prisma/config.yml`. From there it is used for all subsequent requests made by the CLI against Prisma Cloud.

Note that rather than providing your cloud session key via the `--key` flag, you can also set the `PRISMA_CLOUD_SESSION_KEY` environment variable, this is especially useful for CI environments.

### Usage

```sh
prisma login [flags]
```

### Flags

```
-k, --key KEY    Cloud session key
```

### Examples

**Authenticate with Prisma Cloud (opens browser)**

```sh
prisma login
```

**Authenticate with Prisma Cloud by manually passing the cloud session key**

```sh
prisma login --key KEY
```

> In the above command, the `KEY` placeholder needs to be replaced with the value of your valid cloud session key. You can find the `cloudSessionKey` in `~/.prisma/config.yml`.

## prisma logout

Logout from [Prisma Cloud](https://www.prisma.io/cloud). 

This command simply deletes the `cloudSessionKey` from `~/.prisma/config.yml`.

### Usage

```sh
prisma logout
```

### Examples

**Log out of Prisma Cloud**

```sh
prisma logout
```

## prisma console

Opens the [Prisma Cloud Console](https://app.prisma.io/) in the browser.

### Usage

```sh
prisma console
```

### Examples

**Open the Prisma Cloud Console in the browser**

```sh
prisma console
```

## prisma account

Displays account information of the authenticated [Prisma Cloud](https://www.prisma.io/cloud) user (based on the `cloudSessionKey` in `~/.prisma/config.yml`). 

The displayed information includes:

- Username
- Email address

### Usage

```sh
prisma account
```

### Examples

**Display account information of the authenticated Prisma Cloud user**

```sh
prisma account
```